package cn.flying.base.process.listener.eventlistener;

import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @description: 全局事件监听
 * @author: lvyong
 * @date: 2023年02月20日 15:56
 * @version: 1.0
 */
@Component
public class GlobalEventListener implements ActivitiEventListener {
    private Logger logger = LoggerFactory.getLogger(this.getClass());


    /**
     * Called when an event has been fired
     *
     * @param event the event
     */
    @Override
    public void onEvent(ActivitiEvent event) {
        switch (event.getType()) {
            case ENTITY_CREATED:
                System.out.println("ENTITY_CREATED");
                break;
            case ENTITY_ACTIVATED:
                System.out.println("ENTITY_ACTIVATED");
                break;
            case ENTITY_DELETED:
                System.out.println("ENTITY_DELETED");
                break;
            case ENTITY_INITIALIZED:
                System.out.println("ENTITY_INITIALIZED");
                break;
            case ENTITY_SUSPENDED:
                System.out.println("ENTITY_SUSPENDED");
                break;
            case ENTITY_UPDATED:
                System.out.println("ENTITY_UPDATED");
                break;
            case TASK_CREATED:
                System.out.println("TASK_CREATED");
                break;
            case JOB_EXECUTION_FAILURE:
                System.out.println("执行报错了");
                break;
        }
    }

    /**
     * @return whether or not the current operation should fail when this listeners execution throws an exception.
     */
    @Override
    public boolean isFailOnException() {
        return false;
    }
}
